//
//  MOMyGetMarriedProjectEditOrCreatViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/18.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOMyGetMarriedProjectEditOrCreatViewCell.h"

@interface MOMyGetMarriedProjectEditOrCreatViewCell ()<UITextFieldDelegate>

@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UITextField *textField;

@property(nonatomic,assign)CGFloat cellWidth;

@end

@implementation MOMyGetMarriedProjectEditOrCreatViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MOMyGetMarriedProjectEditOrCreatViewCell";
    MOMyGetMarriedProjectEditOrCreatViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MOMyGetMarriedProjectEditOrCreatViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 100, kHConversions(54))];
//    self.nameLabel.backgroundColor = KRedColor_E71020;
    self.nameLabel.textColor = KBlackColor_222222;
    self.nameLabel.font = [UIFont boldSystemFontOfSize:15];
    [self addSubview:self.nameLabel];
    
    self.textField = [[UITextField alloc]initWithFrame:CGRectMake(self.nameLabel.right + 20, 0, SCREEN_WIDTH - 30 - self.nameLabel.width - 20, kHConversions(54))];
    self.textField.delegate = self;
    self.textField.textColor = KBlackColor_222222;
    self.textField.font = FONT_SIZE(15);
    [self addSubview:self.textField];
}

-(void)setModel:(MOMyGetMarriedProjectEditOrCreatViewModel *)model
{
    CGFloat cellWidth = model.cellWidth>0?model.cellWidth:SCREEN_WIDTH;
    
    self.textField.keyboardType = model.KeyboardType;
    
    self.nameLabel.text = model.nameStr;
    
    self.textField.placeholder = model.placeStr;
    
    self.textField.text = model.valueStr;
    
    if ([model.layoutType integerValue]==1) {//左右布局
        
        self.nameLabel.frame = CGRectMake(15, 0, model.labelWidth, kHConversions(54));
        
        self.textField.frame = CGRectMake(self.nameLabel.right + 20, 0, cellWidth - 30 - self.nameLabel.width - 20, kHConversions(54));
        
        self.accessoryType = UITableViewCellAccessoryNone;
        
        self.textField.userInteractionEnabled = YES;
        
    }else if ([model.layoutType integerValue]==2){
        
        self.nameLabel.frame = CGRectMake(15, 0, cellWidth - 30, kHConversions(54));
        
        self.textField.frame = CGRectMake(15, self.nameLabel.bottom, cellWidth - 30, 16);
        
        self.textField.userInteractionEnabled = YES;
        
        self.accessoryType = UITableViewCellAccessoryNone;
        
    }else{
        
        self.nameLabel.frame = CGRectMake(15, 0, model.labelWidth, kHConversions(54));
        
        self.textField.frame = CGRectMake(self.nameLabel.right + 20, 0, cellWidth - 30 - self.nameLabel.width - 20 - 10, kHConversions(54));
        
        self.textField.userInteractionEnabled = NO;
        
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (self.textFieldEndEditingBlock) {
        self.textFieldEndEditingBlock(textField.text);
    }
}


@end
